

export default {
    foreach: function () {
        var strCookie = document.cookie;
        var arrCookie = strCookie.split("; "); // 将多cookie切割为多个名/值对
        for (var i = 0; i < arrCookie.length; i++) { // 遍历cookie数组，处理每个cookie对
            var arr = arrCookie[i].split("=");
            if (arr.length > 0)
                this.DelCookie(arr[0]);
        }
    }
    ,
    GetCooki: function (offset) {
        var endstr = document.cookie.indexOf(";", offset);
        if (endstr == -1)
            endstr = document.cookie.length;
        return decodeURIComponent(document.cookie.substring(offset, endstr));
    }
    ,
    DelCookie: function (name) {
        var exp = new Date();
        exp.setTime(exp.getTime() - 1);
        var cval = this.GetCookie(name);
        document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
    }
    ,
    GetCookie: function (name) {
        var arg = name + "=";
        var alen = arg.length;
        var clen = document.cookie.length;
        var i = 0;
        while (i < clen) {
            var j = i + alen;
            if (document.cookie.substring(i, j) == arg)
                return this.GetCooki(j);
            i = document.cookie.indexOf(" ", i) + 1;
            if (i == 0) break;
        }
        return null;
    },
    toJSON: function (cookie) {
        let cookieArr = cookie.split("; ");
        let obj = {}
        cookieArr.forEach((i) => {
            let arr = i.split("=");
            obj[arr[0]] = arr[1];
        });
        return obj
    }
}